home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Devices / Qwertytunes / BigEasyGrafish.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-03  |  4.6 KB  |  288 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        BigEasyGrafish.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    xxx put writers here xxx
  7.  
  8.     Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     This file is used in these builds: Warhol
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <4>     1/20/92    dvb        Add more routines.
  15.          <3>     5/23/91    PH        changes for THINK 5
  16.          <2>     4/25/91    JB        Changing to new THINK_C interface files
  17.  
  18.     To Do:
  19. */
  20.  
  21. /* file: BigEasyGrafish.c
  22.  *
  23.  * Started 4 August 1989, more or less.
  24.  *
  25.  * A set of routines for doing certain
  26.  * QuickDraw like operations on the Macintosh.
  27.  *
  28.  */
  29.  
  30.  
  31.  
  32. /*--------------------------------
  33.     Inclusions
  34. --------------------------------*/
  35.  
  36. #include <QuickDraw.h>
  37. #include <Resources.h>
  38. #include <Memory.h>
  39. #include <Palettes.h>
  40. #include <GestaltEqu.h>
  41.  
  42. #define BigEasyGrafish
  43.  
  44. #include "BigEasyGrafish.h"
  45.  
  46.  
  47. /*--------------------------------
  48.     Data
  49. --------------------------------*/
  50.  
  51. unsigned char dGrayPat[] = {0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA};
  52. unsigned char dBlackPat[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  53.  
  54.  
  55. /*--------------------------------
  56.     Local Variables & Routines
  57. --------------------------------*/
  58.  
  59. static Boolean GestaltColor(void);
  60. static Boolean gBEGHasColor;
  61. static Boolean gDoneColorGestalt = false;
  62.  
  63.  
  64. /*--------------------------------
  65.     Routines
  66. --------------------------------*/
  67.  
  68. void RGBFore(unsigned short r,unsigned short g,unsigned short b)
  69.     {
  70.     GestaltColor();
  71.     if(gBEGHasColor || 1)
  72.         {
  73.         RGBColor c;
  74.  
  75.         c.red = r;
  76.         c.green = g;
  77.         c.blue = b;
  78.         RGBForeColor(&c);
  79.         }
  80.     else
  81.         {
  82.         unsigned long x;
  83.  
  84.         x = r + g + b;
  85.         if ( x > (3 * 32768))
  86.             ForeColor(whiteColor);
  87.         else
  88.             ForeColor(blackColor);
  89.         }
  90.     }
  91.  
  92. void RGBBack(unsigned short r,unsigned short g,unsigned short b)
  93.     {
  94.     GestaltColor();
  95.     if(gBEGHasColor || 1)
  96.         {
  97.         RGBColor c;
  98.  
  99.         c.red = r;
  100.         c.green = g;
  101.         c.blue = b;
  102.         RGBBackColor(&c);
  103.         }
  104.     else
  105.         {
  106.         unsigned long x;
  107.  
  108.         x = r + g + b;
  109.         if ( x > (3 * 32768))
  110.             BackColor(whiteColor);
  111.         else
  112.             BackColor(blackColor);
  113.         }
  114.     }
  115.  
  116. void GoWhite()
  117.     {
  118.     PenPat(dBlackPat);
  119.     ForeColor(whiteColor);
  120.     }
  121.  
  122. void GoGray()
  123.     {
  124.     PenPat(dBlackPat);
  125.     RGBFore(32768,32768,32768);
  126.     }
  127.  
  128. void GoBlack()
  129.     {
  130.     PenPat(dBlackPat);
  131.     ForeColor(blackColor);
  132.     }
  133.  
  134. void GoBW()
  135.     {
  136.     PenNormal();
  137.     ForeColor(blackColor);
  138.     BackColor(whiteColor);
  139.     }
  140.  
  141. void RGBOp(unsigned short r,unsigned short g,unsigned short b)
  142.     {
  143.     RGBColor c;
  144.     c.red = r;
  145.     c.green = g;
  146.     c.blue = b;
  147.     OpColor(&c);
  148.     }
  149.  
  150. void RGBHilite(unsigned short r,unsigned short g,unsigned short b)
  151.     {
  152.     RGBColor c;
  153.     c.red = r;
  154.     c.green = g;
  155.     c.blue = b;
  156.     HiliteColor(&c);
  157.     }
  158.  
  159. void PmHilite(short h)
  160.     {
  161.     PaletteHandle ph;
  162.     RGBColor c;
  163.  
  164.     ph = GetPalette(FrontWindow());
  165.     GetEntryColor(ph,h,&c);
  166.     HiliteColor(&c);
  167.     }
  168.  
  169.  
  170.  
  171. void RampColorTable(CTabHandle ctH,short start,short length,
  172.         unsigned short r1,unsigned short g1,unsigned short b1,
  173.         unsigned short r2,unsigned short g2,unsigned short b2)
  174. /*
  175.   * Make an rgb ramp in the color table handle passed.
  176.   */
  177.     {
  178.     long dr,dg,db;
  179.     short i;
  180.     ColorSpec *c;
  181.  
  182.     dr = r2-r1;
  183.     dg = g2-g1;
  184.     db = b2-b1;
  185.  
  186.     c = &(**ctH).ctTable[start];
  187.     for(i = 0; i< length; i++)
  188.         {
  189.         c->value = start+i;
  190.         c->rgb.red = r1+ dr*i/length;
  191.         c->rgb.green = g1+ dg*i/length;
  192.         c->rgb.blue = b1+ db*i/length;
  193.         c++;
  194.         }
  195.     }
  196.     
  197. void FrameRectOutside(Rect *r)
  198.     {
  199.     Rect r2;
  200.     PenState ps;
  201.  
  202.     r2 = *r;
  203.     GetPenState(&ps);
  204.     InsetRect(&r2,-ps.pnSize.h,-ps.pnSize.v);
  205.     FrameRect(&r2);
  206.     }
  207.  
  208. void DrawIcl8Resource(short id,Rect *r)
  209. /*
  210.  * Draw the icl8, disregarding masks and such
  211.  */
  212.     {
  213.     PixMap pm;
  214.     Handle h;
  215.  
  216.     h = GetResource('icl8',id);
  217.     if(!h)
  218.         {
  219.         PaintRect(r);
  220.         return;
  221.         }
  222.  
  223.     HLock(h);
  224.  
  225.     pm.baseAddr = *h;
  226.     pm.rowBytes = 32 | 0x8000;
  227.     pm.bounds.top = pm.bounds.left = 0;
  228.     pm.bounds.bottom = pm.bounds.right = 32;
  229.     pm.pmVersion = 0;
  230.     pm.packType = 0;
  231.     pm.packSize = 0;
  232.     pm.hRes = pm.vRes = 0x00480000;
  233.     pm.pixelType = 0;
  234.     pm.pixelSize = 8;
  235.     pm.cmpCount = 1;
  236.     pm.cmpSize = 8;
  237.     pm.planeBytes = 0;
  238.     pm.pmTable = GetCTable(8);
  239.     pm.pmReserved = 0;
  240.  
  241.     CopyBits((void *)&pm,&qd.thePort->portBits,&pm.bounds,r,0,0);
  242.  
  243.     DisposeCTable(pm.pmTable);
  244.     HUnlock(h);
  245.     ReleaseResource(h);
  246.     }
  247.  
  248.  
  249. Boolean EasyHasColor(void)
  250. /*
  251.  * In a nutshell: returns True of the
  252.  * 0,0-point of the current port is
  253.  * anything besides a b/w situation.
  254.  */
  255.     {
  256.     GDHandle gdH;
  257.     Rect r;
  258.     Boolean b;
  259.  
  260.     if(GestaltColor)
  261.         {
  262.         r = qd.thePort->portRect;
  263.         LocalToGlobal((Point *)&r.top);
  264.         LocalToGlobal((Point *)&r.bottom);
  265.         gdH = GetMaxDevice(&r);
  266.         if(gdH)
  267.             b = (**(**gdH).gdPMap).pixelSize > 1;
  268.         else
  269.             b = false;        /* not on any device... whatever */
  270.         }
  271.     else
  272.         b = false;
  273.  
  274.     return b;
  275.     }
  276.  
  277.  
  278. Boolean GestaltColor(void)
  279.     {
  280.     long result;
  281.  
  282.     if(!gDoneColorGestalt)
  283.         gBEGHasColor = (Gestalt('qdrw',&result)) ?
  284.                 false : (result & (1<<gestaltHasDeepGWorlds)) != 0;
  285.  
  286.     return gBEGHasColor;
  287.     }
  288.